<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";

const animationDuration = 6000;

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "300px",
    },
  },
  data() {
    return {
      chart: null,
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");

      this.chart.setOption({
        radar: {
          // shape: 'circle',
          name: {
            textStyle: {
              color: "#808080",
              // backgroundColor: '#999',
              // borderRadius: 3,
              // padding: [3, 5]
            },
          },
          indicator: [
            { name: "挖掘机", max: 6000 },
            { name: "吊车", max: 6000 },
            { name: "叉车", max: 6000 },
            { name: "推土机", max: 6000 },
            { name: "装载机", max: 6000 },
            { name: "装土车", max: 6000 },
            { name: "压路机", max: 6000 },
            { name: "罐车", max: 6000 },
          ],
        },
        series: [
          {
            data: [
              {
                value: [1000, 200, 3000, 5000, 5000, 1000, 2000, 6000],
                label: {
                  normal: {
                    show: false,
                    formatter: function (p) {
                      return p.value;
                    },
                  },
                },
              },
            ],
            label: {
              backgroundColor: "green",
            },
            type: "radar",
            itemStyle: {
              color: "red",
            },
            symbolSize: 0,
            areaStyle: {
              color: "red",
              opacity: 0.3,
            },
          },
        ],
      });
    },
  },
};
</script>
